﻿@model ALinq.BBS.DataAccess.Forum
@using Resources;
@using ALinq.BBS.DataAccess;
@{
    const string FORUMS_LIST = "ForumsList";
    Layout = "_Layout.cshtml";
    var board = (Board)ViewBag.CurrentBoard;
    var boards = (IEnumerable<Board>)ViewBag.Boards;
    var itemID = 0;
    if (ViewBag.ItemID != null)
    {
        itemID = ViewBag.ItemID.Value;
    }
        
}
<style type="text/css">
    .Number
    {
        text-align: center;
        color: #FF5500;
    }
    .LeftPadding
    {
        padding-left: 10px;
    }
</style>
<script type="text/javascript">
    function boardChanged(sender) {
        var sel = document.getElementById('selBoard');
        var selectedIndex = sel.options.selectedIndex;
        if (selectedIndex >= 0) {
            var option = sel.options[selectedIndex];
            var url = "?boardID=" + option.value;
            window.navigate(url);
        }
    }
</script>
<input name="event" type="hidden" value="add" />
<table cellpadding="0" cellspacing="0" style="width: 100%">
    <tr>
        <td colspan="4" class="ListItemHeader">
            版块 &nbsp;
            <select id="selBoard" style="width: 120px" name="boardID" onchange="boardChanged()">
                @if (board == null)
                {
                    <option selected="selected">请选择版块</option>
                }
                @foreach (var item in boards)
                {
                    if (item == board)
                    {
                    <option value="@item.ID" selected="selected">@item.Name</option>
                    }
                    else
                    {
                    <option value="@item.ID">@item.Name</option>
                    }
                }
            </select>
        </td>
    </tr>
</table>
@using (Html.BeginForm())
{
    <input name="ItemID" type="hidden" value="@ViewBag.ItemID" />
    <table cellpadding="0" cellspacing="0" style="width: 100%">
        <tr>
            <td class="ListItemHeader_l">
                名称
            </td>
            <td class="ListItemHeader_m" style="width: 80px">
                子版块数
            </td>
            <td class="ListItemHeader_m" style="width: 80px; text-align: center;">
                @Resources.Label.PostsCount
            </td>
            <td class="ListItemHeader_r" style="width: 120px">
            </td>
        </tr>
        @if (board != null)
        {
            foreach (var item in board.Forums.Where(o => o.Parent == null))
            {
            <tr>
                <td class="ListItem LeftPadding">
                    @if (item.ID == ViewBag.EditItemID)
                    {
                        @Html.TextBoxFor(o => o.Name)
                    }
                    else
                    {
                        @item.Name
                    }
                </td>
                <td class="ListItem Number">
                    @item.Children.Count
                </td>
                <td class="ListItem Number">
                    @item.Posts.Count
                </td>
                <td class="ListItem">
                    @if (item.ID == ViewBag.EditItemID)
                    {
                        <input type="hidden" name="ID" value="@item.ID" />
                        <a href="javascript:document.getElementsByTagName('form')[0].submit()">@Label.Update</a>
                        <span>&nbsp;</span>//updateForm
                        @Html.ActionLink(Label.Cancle, FORUMS_LIST, new { boardID = board.ID })
                    }
                    else
                    {
                        @Html.ActionLink(Label.Edit, FORUMS_LIST, new { boardID = board.ID, editItemID = item.ID })
                        //if (item.Posts.Count == 0)
                        //{
                        <span>&nbsp;</span>
                        @Html.ActionLink(Label.Delete, FORUMS_LIST, new { boardID = board.ID, deleteItemID = item.ID })
                        //}
                    }
                </td>
            </tr>
            }
            if (Model == null)
            {
            <tr>
                <td class="ListItem LeftPadding">
                    @Html.TextBoxFor(o => o.Name)
                    &nbsp;
                    @Html.ValidationMessageFor(o => o.Name)
                </td>
                <td class="ListItem Number">
                    0
                </td>
                <td class="ListItem Number">
                    0
                </td>
                <td class="ListItem">
                    @*<a href="javascript:document.getElementsByTagName('form')[0].submit()">@Label.Add</a>*@
                    <input name="Event" type="submit" value="@Label.Add" />
                </td>
            </tr>
            }
            <tr>
                <td colspan="4">
                    <hr class="spliter" />
                </td>
            </tr>
            <tr>
                <td colspan="4" class="ListItemHeader" style="text-align: right;">
                    &nbsp;
                </td>
            </tr>
        }
    </table>

}